|
|
 |
|
|
|
|
End If
' Solve for t. t = -(A * px + B * py + C * pz + D) / denom
' If there is no positive t value, there's no
' intersection in this direction. If t < 0.01 Then
RayTraceable_FindT = -1
Exit Function
End If
' We had a hit. If direct_calculation Then HadHit = True
RayTraceable_FindT = t
End Function |
|
|
|
|
|
|
|
|
There is one significant difference between the FindHitColor functions used by the RayPlane and RaySphere classes. After finding the plane's normal vector, the RayPlane class makes sure that the vector points in the direction of the center of projection. That allows the CalculateHitColor subroutine to color the plane correctly. If the center of projection and a light source lie on opposite sides of the plane, using this normal allows the program to correctly omit the specular and diffuse reflection components in the plane's lighting model. The plane blocks the light source, so it receives only ambient light. |
|
|
|
 |
|
|
|
|
' Return the red, green, and blue components of
' the surface at the hit position. Public Sub RayTraceable_FindHitColor(ByVal depth As Integer, _
Objects As Collection, ByVal eye_x As Single, _
ByVal eye_y As Single, ByVal eye_z As Single, _
ByVal px As Single, ByVal py As Single, _
ByVal pz As Single, ByRef R As Integer, _
ByRef G As Integer, ByRef B As Integer)
Dim Nx As Single
Dim Ny As Single
Dim Nz As Single
Dim Vx As Single
Dim Vy As Single
Dim Vz As Single
Dim NdotV As Single
' Find the unit normal at this point. GetUnitNormal Nx, Ny, Nz
' Make sure the normal points towards the
' center of projection. Vx = EyeX - px
Vy = EyeY - py
Vz = EyeZ - pz |
|
|
|
|
|